<!DOCTYPE html>
<html xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include/src :: form_base_js_and_css"/>
</head>
<body style="background-color: #f2f2f2; height: 100%;">

<div id="id_panel">
</div>
<script th:inline="javascript">
	var dto = $.parseJSON(JSON.stringify([[${dto}]]));
	//只有流转中才能
	if (dto.flowRefuseBtn.state == 1 && dto.saveBtn.state != 1){
		dto.saveBtn.state = 1;
	}
	// 表单初始化
	var formObj = null;
	//使用layui的sku模块
	layui.config({
		//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
		base: '/static/js/layui_extends/',
		version: true
	}).use(['form', 'jquery', 'laydate', 'YsForm', 'YsModal'], function(){
		var $ = layui.jquery,
				form = layui.form,
				laydate = layui.laydate,
				YsForm = layui.YsForm,
				YsModal = layui.YsModal;
		/*
		* 表单初始化
		* 参数1：表单配置参数
		* 参数2：子表配置参数
		*/
		formObj = YsForm.init(
				{
					id:'id_panel', // 页面容器ID
					dto: dto
				}
		);




		var newOptions = [
			{name: "支付宝", value: "0"},
			{name: "跨境宝", value: "1"},
		];

		var newOptions1 = {name: "支付宝", value: "0"};

		var refundPayTypeTo = formObj.getValueByName("refundPayTypeTo");
		var payTypeName = formObj.getValueByName("payTypeName");
		// 清空原有选项
		$('#refundPayType').empty();

		// if (refundPayTypeTo == '1'){
		if (payTypeName == '跨境宝'){
			// 添加新的选项
			for(var i = 0; i < newOptions.length; i++){
				if (i == Number(refundPayTypeTo)){
					$('#refundPayType').append('<option selected value="' + newOptions[i].value + '">' + newOptions[i].name + '</option>');
				}else {
					$('#refundPayType').append('<option value="' + newOptions[i].value + '">' + newOptions[i].name + '</option>');
				}
			}
		}else {
			$('#refundPayType').append('<option selected value="' + newOptions1.value + '">' + newOptions1.name + '</option>');
		}

		// 更新select元素
		form.render('select');


		form.on('select(_input_filter_selector_on_form)', function(data) {
			var name = $(data.elem).attr('name');
			if (name == 'refundPayType'){
				//监听付款方式
				var refundPayType = formObj.getValueByName("refundPayType");
				var payTypeName = formObj.getValueByName("payTypeName");
				if (payTypeName == '跨境宝'){
					formObj.setValueByName("refundVyhzh",null);
					formObj.setValueByName("refundVyhzhmc",null);
					formObj.setValueByName("refundVkhh",null);
					formObj.setValueByName("refundVid",null);
				}
			}else if (name == 'isRefund'){
				//重新获取一遍数据
				var purchaseOrderBid = formObj.getValueByName("purchaseOrderBid");
				if (purchaseOrderBid != undefined){
					calFormItem()
				}
			}
		});

		formObj.matchValuesAfterModalSelectRadio = function(colCode, rowSelected, extraData) {
			var t = formObj;
			var domForm = $('#' + t.c.id_form);
			if (colCode == 'refundVyhzh'){
				domForm.find('input[name="refundVyhzh"]').val(rowSelected.vyhzh);
				domForm.find('input[name="refundVyhzhmc"]').val(rowSelected.vyhzhmc);
				domForm.find('input[name="refundVkhh"]').val(rowSelected.vkhh);
				domForm.find('input[name="refundVid"]').val(rowSelected.vid);
			}else if (colCode == 'purchaseOrderBid'){
				for(var i = 0; i < t.c.dto.rows.length; i++){
					var col = t.c.dto.rows[i];
					if (col.code == colCode) {
						// 给选择框设置的字段赋值
						domForm.find('input[name="' + colCode + '"]').val(rowSelected[col.modalValueCode]);
					} else if(col.modalRelativeCode == colCode) {
						domForm.find('input[name="' + col.code + '"]').val(rowSelected[col.modalValueCode]);
					}
				}

				// 清空原有选项
				$('#refundPayType').empty();

				if (rowSelected.payTypeName == '跨境宝'){
					// 添加新的选项
					for(var i = 0; i < newOptions.length; i++){
						if (i != 0){
							$('#refundPayType').append('<option selected value="' + newOptions[i].value + '">' + newOptions[i].name + '</option>');
						}else {
							$('#refundPayType').append('<option value="' + newOptions[i].value + '">' + newOptions[i].name + '</option>');
						}
					}
				}else {
					$('#refundPayType').append('<option selected value="' + newOptions1.value + '">' + newOptions1.name + '</option>');
				}

				// 更新select元素
				form.render('select');

				//查询子件逻辑
				calFormItem();
			}
		};

		//重写弹出框
		formObj.showModal=function(modalKey, colCode) {
			var t = formObj;
			if(colCode == 'refundVyhzh'){//退款付款账户编码弹框
				var refundPayType = formObj.getValueByName("refundPayType");//退款方式
				if(refundPayType == '0'){
					layui.YsModal.init({modalKey: modalKey, colCode: colCode, parentObj: t, extraData:{}, conditionsDefault: [], sameCode: 'xx', pathGridRequest: '/api/inter/tbCompanyBankInfo/searchForNeedPay?vid='+ 'DGZH0052'});
				}else {
					return layer.msg("退款方式为跨境宝时，不允许修改!");
				}
			} else{
				// 打开单选框,
				layui.YsModal.init({modalKey: modalKey, colCode: colCode, parentObj: t, extraData:{}, conditionsDefault: [{code: 'aaa', value:'123'},{code: 'bbb', value:'456'}], sameCode: 'xx'});
			}
		}

		/*
		 * 监听输入框
		 */
		var domForm = $('#' + window.formObj.c.id_form);
		domForm.find('input[name="refundAmount"]').on('change',function (e) {
			pData();
		});

		domForm.find('input[name="refundServiceCharge"]').on('change',function (e) {
			pData();
		});
	});


</script>

<script type="text/javascript" src="/static/js/storage/tccOnlinePurchaseReturn/form-listen.js?v=20241121"></script>


</body>
</html>